__author__ = 'chonglei'
# 短信发送方法
# import sys

# sys.path.append('/root/hostmonitor/libs')

from libs.suds.client import Client
from conf.config_default import configs
import base64
import time

localtime = time.asctime(time.localtime(time.time()))
configs = configs

url = configs['smswebservice']['url']
syscode = configs['smswebservice']['syscode']
syspwd = configs['smswebservice']['syspwd']
basesyspwd = base64.b64encode(syspwd.encode('utf-8'))
pwdstr = str(basesyspwd, 'utf-8')


# SendOne(String SenderName,String Phone,String Content,String SysCode,String SysPwd,String ReceiverName)
# 发送人姓名,接收人手机号码,短信内容,服务代码,授权密码,接收人姓名
def sms_send_one(sendname, phonenum, smscontent):
    sendname = str(sendname)
    phonenum = str(phonenum)
    smscontent = str(smscontent)
    try:
        client = Client(url)
        servicesms = client.service
    except BaseException as e:
        print(e)
    try:
        result = servicesms.SendOne(sendname, phonenum, smscontent, syscode, pwdstr, 'admin')
        print(result)
    except WebFault as e:
        print(e.fault)
        print(e.document)
    # print(localtime + ': ' + '已发送至: ')


if __name__ == '__main__':
    sms_send_one('chong', '13659311603', 'testsms1 %s' % localtime)
